package com.chengzzz.mysite.exception;

import com.alibaba.fastjson.JSONObject;
import com.chengzzz.mysite.enums.ResultEnum;
import com.chengzzz.mysite.result.Result;
import org.apache.shiro.authz.AuthorizationException;
import org.apache.shiro.authz.UnauthenticatedException;
import org.apache.shiro.authz.UnauthorizedException;
import org.mybatis.logging.Logger;
import org.mybatis.logging.LoggerFactory;
import org.springframework.beans.ConversionNotSupportedException;
import org.springframework.beans.TypeMismatchException;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.http.converter.HttpMessageNotWritableException;
import org.springframework.web.HttpMediaTypeNotAcceptableException;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * <p>
 * 全局异常处理
 * </p>
 *
 * @author 等什么柠檬君
 * @since 2020/8/26
 */

@ControllerAdvice
public class GlobalExceptionHandler  {

    @ExceptionHandler({ UnauthorizedException.class, AuthorizationException.class })
    @ResponseBody
    public Result UnauthorizedExcepitonHandler(HttpServletRequest request,Exception e) {
        return new Result(ResultEnum.ERROR.getCode(),"你他妈的没有权限",e.fillInStackTrace(),false);
    }



    @ExceptionHandler(HttpRequestMethodNotSupportedException.class)
    @ResponseBody
    public Throwable HttpRequestMethodNotSupportedExceptionHandler(HttpServletRequest request,Exception e) {
        return e.fillInStackTrace();
    }



    @ExceptionHandler(Exception.class)
    @ResponseBody
    public String defultExcepitonHandler(HttpServletRequest request,Exception e) {
        return "全局异常处理"+e.getMessage()+e.fillInStackTrace();
    }


}
